import csv

def Open():
    path = input("请输入CSV文件路径：").strip()
    with open(path, 'r', encoding='utf-8') as file:
        reader = csv.reader(file)
        header = file.readline().strip()
        #[[],[],[]]
        data = list(reader) #除表头外数据
    return header,data
def Str():
    # 设置缺省值，作为默认值
    default_str1=''
    default_str2=''
    one_str1=input('格式前缀1：')
    two_str2=input('格式前缀2：')
    if one_str1:
        str1=one_str1
    else:
        str1=default_str1
    if two_str2:
        str2=two_str2
    else:
        str2=default_str2
    return str1,str2
def Handle(header,data,str1,str2):
    target_num = input("输入num: ").strip()
    all_results = []
    num_list = [num.strip() for num in target_num.replace(',',' ').split()]  # 分割成列表
    for num in num_list:
        # 查找匹配的行
        found_rows = []
        for row in data:
            if len(row) > 2 and row[2] == num:  # 检查是否有足够列
                found_rows.append(row)
        if found_rows:
            for row in found_rows:
                #添加新列就在这里添加下标
                all_results.append((num, row[1], row[0]))
    if all_results:
        print("\n匹配的数据：")
        print(header)
        values1 = "/".join([res[1] for res in all_results])
        values2 = "/".join([res[2] for res in all_results])
        print('\n')
        print(f'{str1}：{values1}')
        print(f'{str2}：{values2}')
        print('\n')
    else:
        print(f"\n未找到数据")
    return target_num

if __name__ == '__main__':
    try:
        header,data=Open()
        str1,str2=Str()
        while 1:
            num=Handle(header,data,str1=str1,str2=str2)
            if num=='q':
                break
    except KeyboardInterrupt:
        print('中断')
